import {EditorState} from "prosemirror-state"
import {EditorView} from "prosemirror-view"
import {Schema, DOMParser} from "prosemirror-model"
import {schema} from "prosemirror-schema-basic"
import {addListNodes} from "prosemirror-schema-list"
import {exampleSetup} from "prosemirror-example-setup"
export function initEditor(domSelector, contentSelector) {
  const mySchema = new Schema({
    nodes: addListNodes(schema.spec.nodes, "paragraph block*", "block"),
    marks: schema.spec.marks
  })
  const view = new EditorView(document.querySelector(domSelector), {
    state: EditorState.create({
      doc: DOMParser.fromSchema(mySchema).parse(document.querySelector(contentSelector)),
      plugins: exampleSetup({schema: mySchema})
    })
  })
  return {
    schema:mySchema,
    view,
  }

}